
from homeassistant.const import (ATTR_ENTITY_ID,ATTR_FRIENDLY_NAME,ATTR_DOMAIN)

from .const import (
    NULL_VALUE ,
)

def get_props(cur_dev,dev):
        """返回属性
        """
        if dev['name'] == 'power':
            dev['value']  = 'on' if cur_dev['state'] == 'open' else 'off'

        elif dev['name'] == 'current_position':
            dev['value'] = cur_dev['attributes']['current_position']  if 'current_position' in cur_dev['attributes'] else NULL_VALUE

        elif dev['name'] == 'set_position':
            dev['value'] = cur_dev['attributes']['set_position'] if 'set_position' in cur_dev['attributes'] else NULL_VALUE

        else:
            dev['value'] = NULL_VALUE
        return dev


def set_props_to_call_service_data(cur_dev,dev):
    """设置开关
    """
    domain = cur_dev[ATTR_ENTITY_ID].split('.')[0]
    
    data = {ATTR_ENTITY_ID:cur_dev[ATTR_ENTITY_ID]}
    service = ''
    if dev['name'] == 'power':
        service = 'open_cover' if dev['value'] == 'on' else 'close_cover'
        
    elif dev['name'] == 'control':
        
        if dev['value'] == 2:
            service = 'close_cover'
        elif dev['dev'] == 0:
            service = 'stop_cover'
        elif dev['dev'] == 1:
            service = 'open_cover'

    elif dev['name'] == 'set_position':
        service = 'set_cover_position'
        data ['position']=dev['value']

    return [domain,service,data]